package com.huizu.pay.util;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;

public class Sign {
	public static String createSign(SortedMap<String, Object> packageParams, String API_KEY) {
		StringBuffer sb = new StringBuffer();
		Set<Map.Entry<String, Object>> es = packageParams.entrySet();
		Iterator<Map.Entry<String, Object>> it = es.iterator();
		while (it.hasNext()) {
			Map.Entry<String, Object> entry = (Map.Entry<String, Object>) it.next();
			Object ok = entry.getKey();
			String k = ok == null ? null : ok.toString();
			Object ov = entry.getValue();
			String v = ov == null ? null : ov.toString();
			if (null != v && !"".equals(v) && !"sign".equals(k) && !"key".equals(k)) {
				sb.append(k + "=" + v + "&");
			}
		}
		sb.append("key=" + API_KEY);
		String sign = Md5Util.MD5Encode(sb.toString(), "utf-8").toUpperCase();
		return sign;
	}
}
